PATHMac OS 8 and 9 Developer Documentation > Networking and Communications > URL Access Manager >

Transferring Files With the URL Access Manager


Displaying a URL's Properties

Given a URL reference, the displayProperties routine creates a propertyList array with one element for each of the twenty-one URL Access properties defined by Apple Computer. Then the routine gets the size of each property by calling URLGetPropertySize , gets the value of each property by calling URLGetProperty . and displays each property value.

Listing 2-13  Displaying the value of each URL property

void displayProperties( URLReference urlRef )
{
    OSErr err = noErr;
    int propCount = 0;
    const char* propertyList[21];
    Size propertySize = 0;
    Handle theProperty = nil;
    propertyList[0] = kURLURL;
    propertyList[1] = kURLResourceSize;
    propertyList[2] = kURLLastModifiedTime;
    propertyList[3] = kURLMIMEType;
    propertyList[4] = kURLFileType;
    propertyList[5] = kURLFileCreator;
    propertyList[6] = kURLCharacterSet;
    propertyList[7] = kURLResourceName;
    propertyList[8] = kURLHost;
    propertyList[9] = kURLAuthType;
    propertyList[10] = kURLUserName;
    propertyList[11] = kURLPassword;
    propertyList[12] = kURLStatusString;
    propertyList[13] = kURLIsSecure;
    propertyList[14] = kURLCertificate;
    propertyList[15] = kURLTotalItems;
    propertyList[16] = kURLHTTPRequestMethod;
    propertyList[17] = kURLHTTPRequestHeader;
    propertyList[18] = kURLHTTPRequestBody;
    propertyList[19] = kURLHTTPRespHeader;
    propertyList[20] = kURLHTTPUserAgent;

    // Get the size of each property, allocate a handle to store the
    // property's value, get the property value, and display it.
    for( propCount = 0; propCount < 21; propCount++)
    {
        // Get the size of the property's value.
        err = URLGetPropertySize(urlRef, propertyList[propCount], &propertySize);
        if(err != noErr)
            printf("Error %d getting property size %s. Size returned
                was: %d\n", err, propertyList[propCount], propertySize);
        else
            printf("Property size is %d: %s\n", propertySize);

        // Now get a handle for the property value.
        theProperty = NewHandleClear( propertySize + 1 );
        err = MemError();
        if(err != noErr)
            printf("Error %d getting property handle %s\n", err,
                propertyList[propCount]);
        else
            printf("Got handle for %s: %s\n", propertyList[propCount]);

        // Now get the property's value.
        err = URLGetProperty(urlRef, propertyList[propCount],
                *theProperty, propertySize);
        if(err != noErr)
            printf("Error %d getting property %s\n", err, propertyList[propCount]);
        else
            printf("Property %s: %s\n", propertyList[propCount], *theProperty);

        // Clean up.
        DisposeHandle(theProperty);
        printf("\n");
    }
    return;
}


© 1999 Apple Computer, Inc. – (Last Updated 07 May 99)